{% include 'typescript.header.j2' %}

import { deleteRequest, getRequest, postRequest, putRequest } from '@/utils/request';
import { req } from "@/api/manage";
import { {{ table.derived.naming.class_name }} } from './{{ table.derived.naming.class_name }}';
import {
  getMock{{ table.derived.naming.class_name }}Data,
  mockAdd{{ table.derived.naming.class_name }},
  mockEdit{{ table.derived.naming.class_name }},
  mockDelete{{ table.derived.naming.class_name }},
  mockFetch{{ table.derived.naming.class_name }}Detail
} from './mockData';

// 是否使用Mock数据
const USE_MOCK_DATA = false;
const USE_REQ_FLAG = false;

interface {{ table.derived.naming.class_name }}QueryParams {
  pageNumber: number;
  pageSize: number;
  studentNo?: string;
  name?: string;
  grade?: string;
}

// 获取{{ table.common.label }}列表
export const api{{ table.derived.naming.class_name }}FetchList = (params: {{ table.derived.naming.class_name }}QueryParams) => {
  if (USE_MOCK_DATA) {
    return getMock{{ table.derived.naming.class_name }}Data(params.pageNumber, params.pageSize);
  }
  return getRequest('/api/anon/{{ table.mark.business_name }}', params);
};

// 添加{{ table.common.label }}
export const api{{ table.derived.naming.class_name }}Add = (data: Partial<{{ table.derived.naming.class_name }}>) => {
  if (USE_MOCK_DATA) {
    return mockAdd{{ table.derived.naming.class_name }}(data);
  }
  return postRequest('/api/anon/{{ table.mark.business_name }}', data);
};

// 编辑{{ table.common.label }}
export const api{{ table.derived.naming.class_name }}Edit = (id: number, data: Partial<{{ table.derived.naming.class_name }}>) => {
  if (USE_MOCK_DATA) {
    return mockEdit{{ table.derived.naming.class_name }}(id, data);
  }
  return putRequest(`/api/anon/{{ table.mark.business_name }}/${id}`, data);
};

// 删除{{ table.common.label }}
export const api{{ table.derived.naming.class_name }}Delete = (id: number) => {
  if (USE_MOCK_DATA) {
    return mockDelete{{ table.derived.naming.class_name }}(id);
  }
  if (USE_REQ_FLAG) {
    return req.delById('/api/anon/{{ table.mark.business_name }}', id);
  }
  return deleteRequest(`/api/anon/{{ table.mark.business_name }}/${id}`);
};

// 获取{{ table.common.label }}详情
export const api{{ table.derived.naming.class_name }}FetchDetail = (id: number) => {
  if (USE_MOCK_DATA) {
    return mockFetch{{ table.derived.naming.class_name }}Detail(id);
  }
  return getRequest(`/api/anon/{{ table.mark.business_name }}/${id}`);
};

